﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class Admin_User_User_Manager : System.Web.UI.Page
{
    public int _userId = 0;
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    DepartmentInfoManager dllDepartmentInfoManager = new DepartmentInfoManager();
    JobManager dllJobManager = new JobManager();
    RoleManager dllRoleManager = new RoleManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    Authentication dllAuthentication = new Authentication();
    PositionManager dllPositionManager = new PositionManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isAdminLogin();
        this.btnAdd.Enabled = false;
        this.btnchongzhi.Enabled = true;
        this.btnDelete.Enabled = false;
        this.btnOk.Enabled = false;
        this.btnSelect.Enabled = false;
        _powerTable = dllAuthentication.getPower(objUserInfo.UserName, "用户管理");
        for (int i = 0; i < _powerTable.Rows.Count; i++)
        {
            if (_powerTable.Rows[i]["PowerName"].ToString() == "新建")
            {
                this.btnAdd.Enabled = true;
                this.btnOk.Enabled = true;
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "删除")
            {
                this.btnDelete.Enabled = true;
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "查看")
            {
                this.btnUnDimission.Enabled = true;
                this.btnSelect.Enabled = true;
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "修改")
            {
                this.btnOk.Enabled = true;
            }
        }

        if (!IsPostBack)
        {
            BindGridView();
            BindDropDownList();
        }
    }
    /// <summary>
    /// 绑定GridView
    /// </summary>
    /// <author>gzz</author>
    /// <date>2008-12-30</date>
    void BindGridView()
    {
        //this.gdvUserName.DataSource = dllUserInfoManager.get();
        //this.gdvUserName.DataBind();

        //for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        //{
        //    if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
        //    {
        //        this.gdvUserName.Rows[i].Cells[10].Text = "是";
        //    }
        //    else
        //    {
        //        this.gdvUserName.Rows[i].Cells[10].Text = "否";
        //    }
        //}
        //该事件需要两个参数，一个输入的关键字，另一个是判断的查询条件
        //声明一个Datatable，
        DataTable _select = new DataTable();
        //第一个参数：获得输入的关键字
        object[] _value = new object[1];

        //第二个参数：判断查询条件
        if (this.drpSelect.SelectedItem.Text == "选择查询条件")
        {
            //Utility.HttpHelp.alert("请选择查询条件", Page);
            //_select = dllUserInfoManager.get();
        }
        if (this.drpSelect.SelectedItem.Text == "登录名称")
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = txtSelect_Content.Text.Trim();
                _value[0] = "%" + _value[0] + "%";
                _select = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
            }

        }
        if (this.drpSelect.SelectedIndex == 2)
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = txtSelect_Content.Text.Trim();
                _value[0] = "%" + _value[0] + "%";
                _select = dllUserInfoManager.get(UserInfoManager.field.RealName.ToString(), _value);
            }

        }
        if (this.drpSelect.SelectedItem.Text == "人员编号")
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = Convert.ToInt32(txtSelect_Content.Text.Trim());
                _select = dllUserInfoManager.get(UserInfoManager.field.UserId.ToString(), _value);
            }
        }
        if (this.drpSelect.SelectedItem.Text == "主岗名称")
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = this.drpTarget.SelectedItem.Text;
                _select = dllUserInfoManager.get(UserInfoManager.field.MasterJob.ToString(), _value);
            }

        }
        if (this.drpSelect.SelectedItem.Text == "职位级别")
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = this.drpTarget.SelectedItem.Text;
                _select = dllUserInfoManager.get(UserInfoManager.field.PostLevel.ToString(), _value);
            }

        }
        if (this.drpSelect.SelectedItem.Text == "部门名称")
        {
            if (_select.Rows.Count == 0)
            {
                if (this.txtContent.Value.Length > 0)
                {
                    _value[0] = this.txtContent.Value.Trim();
                    _select = dllUserInfoManager.getUserInfoByDepartmentName(_value);
                }
                else
                {
                    _select = dllUserInfoManager.get();
                }
            }
        }
        if (this.drpSelect.SelectedItem.Text == "副岗名称")
        {
            if (_select.Rows.Count == 0)
            {
                _value[0] = this.drpTarget.SelectedItem.Text;
                _select = dllUserInfoManager.get(UserInfoManager.field.PartTimeDepartmentId.ToString(), _value);
            }
        }
        if (this.drpIsDimission.SelectedItem.Text == "在职")
        {
            if (_select.Rows.Count == 0)
            {
                this.btnUnDimission.Enabled = false;
                this.btnIsDimission.Enabled = true;
                object[] _valueuser = new object[1];
                _valueuser[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
                _select = dllUserInfoManager.get();
            }
        }
        if (this.drpIsDimission.SelectedItem.Text == "离职")
        {
            if (_select.Rows.Count == 0)
            {
                this.btnUnDimission.Enabled = true;
                this.btnIsDimission.Enabled = false;

                object[] _valueuser = new object[1];
                _valueuser[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
                _select = dllUserInfoManager.get(UserInfoManager.field.IsDimission.ToString(), _valueuser);
            }
        }

        //查询的结果绑定到gridview中
        this.gdvUserName.DataSource = _select;
        this.gdvUserName.DataBind();
        for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        {
            if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "是";
            }
            else
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "否";
            }
        }
    }

    /// <summary>
    /// 绑定所有的DropDownList
    /// </summary>
    void BindDropDownList()
    {
        this.drpRole.Items.Clear();
        //绑定角色
        this.drpRole.DataSource = dllRoleManager.get();
        this.drpRole.DataTextField = "RoleName";
        this.drpRole.DataValueField = "RoleId";
        this.drpRole.DataBind();

        //绑定职务
        this.drpPostLevel.DataSource = dllPositionManager.get();
        this.drpPostLevel.DataTextField = "PositionName";
        this.drpPostLevel.DataValueField = "PositionId";
        this.drpPostLevel.DataBind();
    }

    /// <summary>
    /// 根据用户id绑定DropDownList对应的值
    /// </summary>
    void Bind(string _userId)
    {
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(_userId);
        DataTable user_table = dllUserInfoManager.get(UserInfoManager.field.UserId.ToString(), _value);
        if (user_table.Rows.Count != 0)
        {
            if (user_table.Rows[0]["UserName"].ToString() == "admin" || user_table.Rows[0]["UserName"].ToString() == "system")
            {
                this.txtUserName.Text = user_table.Rows[0]["UserName"].ToString();
                this.txtRealName.Text = user_table.Rows[0]["RealName"].ToString();

                this.txtUserPassWord.Attributes.Add("value", user_table.Rows[0]["UserPassWord"].ToString());
                this.txtReUserPassWord.Attributes.Add("value", user_table.Rows[0]["UserPassWord"].ToString());
                this.txtUserName.Enabled = false;

                //绑定该用户的部门
                this.txtDepartment.Value = "";
                this.txtDepartment.Disabled = true;
                //绑定兼职部门
                this.txtPartTimeDepartment.Value = "";
                this.txtPartTimeDepartment.Disabled = true;
                //绑定该用户的主岗
                this.txtMasterJob.Value = "";
                this.txtMasterJob.Disabled = true;
                //绑定该用户的副岗
                this.txtSlaveJob.Value = "";
                this.txtSlaveJob.Disabled = true;


                //绑定该用户的职务
                ListItem _li = new ListItem();
                this.drpPostLevel.Items.Clear();
                this.drpPostLevel.Items.Add(_li);
                //绑定该用户的主管
                this.drpIsDepartmentManager.SelectedIndex = this.drpIsDepartmentManager.Items.IndexOf(this.drpIsDepartmentManager.Items.FindByValue(user_table.Rows[0]["IsDepartmentManager"].ToString()));

                //绑定角色组
                this.drpRole.SelectedIndex = this.drpRole.Items.IndexOf(this.drpRole.Items.FindByText(user_table.Rows[0]["RoleName"].ToString()));
                this.drpRole.Enabled = false;
            }
            else
            {
                BindDropDownList();
                this.txtUserName.Text = user_table.Rows[0]["UserName"].ToString();
                this.txtRealName.Text = user_table.Rows[0]["RealName"].ToString();
                this.txtItCode.Text = user_table.Rows[0]["ItCode"].ToString();
                this.txtUserPassWord.Attributes.Add("value", user_table.Rows[0]["UserPassWord"].ToString());
                this.txtReUserPassWord.Attributes.Add("value", user_table.Rows[0]["UserPassWord"].ToString());
                this.txtUserName.Enabled = false;
                //绑定该用户的部门
                this.txtDepartment.Disabled = false;
                this.txtDepartment.Value = user_table.Rows[0]["DepartmentId"].ToString();
                //绑定兼职部门
                this.txtPartTimeDepartment.Disabled = false;
                this.txtPartTimeDepartment.Value = user_table.Rows[0]["PartTimeDepartmentId"].ToString();
                //绑定该用户的主岗
                this.txtMasterJob.Disabled = false;
                this.txtMasterJob.Value = user_table.Rows[0]["MasterJob"].ToString();
                //绑定该用户的副岗
                this.txtSlaveJob.Disabled = false;
                this.txtSlaveJob.Value = user_table.Rows[0]["SlaveJob"].ToString();


                //绑定该用户的职务
                this.drpPostLevel.SelectedIndex = this.drpPostLevel.Items.IndexOf(this.drpPostLevel.Items.FindByText(user_table.Rows[0]["PostLevel"].ToString()));
                //绑定该用户的主管
                this.drpIsDepartmentManager.SelectedIndex = this.drpIsDepartmentManager.Items.IndexOf(this.drpIsDepartmentManager.Items.FindByValue(user_table.Rows[0]["IsDepartmentManager"].ToString()));

                //绑定角色组
                this.drpRole.Enabled = true;
                this.drpRole.SelectedIndex = this.drpRole.Items.IndexOf(this.drpRole.Items.FindByText(user_table.Rows[0]["RoleName"].ToString()));
            }
        }
        else
        {
            Utility.HttpHelp.alert("该用户已离职，请先恢复为在职，在查看！", this.Page);
        }

    }



    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvUserName_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvUserName.PageIndex = e.NewPageIndex;
        BindGridView();
    }


    /// <summary>
    /// 提交按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        //判断是否为新增用户
        if (this.hId.Value.Length == 0)
        {
            #region
            if (this.txtUserPassWord.Text.Trim().Length == 0)
            {
                this.RequiredFieldValidator2.Validate();
                return;
            }
            if (this.txtReUserPassWord.Text.Trim().Length == 0)
            {
                this.RequiredFieldValidator3.Validate();
                return;
            }
            if (dllUserInfoManager.isExist(txtUserName.Text.Trim()) == 1)
            {
                ScriptManager.RegisterStartupScript(this.btnOk, this.btnOk.GetType(), "alert", "alert('该用户已存在');", true);
                return;
            }
            object[] _User = new object[11];//定义一个数组
            _User[0] = txtUserName.Text.Trim();
            //加密密码
            //_User[1] = Authentication.EncryptPassword(txtUserPassWord.Text, Authentication.EncryptType.MD5);
            _User[1] = txtUserPassWord.Text;
            if (this.txtDepartment.Value.Length == 0)
            {
                ScriptManager.RegisterStartupScript(this.btnOk, this.btnOk.GetType(), "alert", "alert('请选择部门');", true);
                return;
            }
            //根据部门名称查询部门id，和兼职部门id
            object[] _valueDepartment = new object[1];
            _valueDepartment[0] = this.txtDepartment.Value;
            DataTable _department = dllDepartmentInfoManager.get(DepartmentInfoManager.field.DepartmentName.ToString(), _valueDepartment);
            _User[2] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
            _valueDepartment[0] = this.txtPartTimeDepartment.Value;
            _department = dllDepartmentInfoManager.get(DepartmentInfoManager.field.DepartmentName.ToString(), _valueDepartment);
            if (_department.Rows.Count > 0)
            {
                _User[3] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
            }
            else
            {
                _User[3] = 0;
            }
            _User[4] = this.txtMasterJob.Value.Trim();
            _User[5] = this.txtSlaveJob.Value.Trim();
            _User[6] = drpPostLevel.SelectedItem.Text;
            _User[7] = int.Parse(drpIsDepartmentManager.SelectedValue.ToString());
            _User[8] = txtRealName.Text;
            _User[9] = this.drpRole.SelectedItem.Text;
            _User[10] = this.txtItCode.Text.Trim();
            int result = dllUserInfoManager.add(_User);//调用方法，引用存储过程，把读取的值赋给存储过程中的值
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("添加用户未成功，请重试！");
            }
            else
            {
                Utility.HttpHelp.alert("添加成功！", Page);
                BindGridView();
            }
            #endregion
        }
        else
        {
            //判断如果没有填写密码,则不更新密码

            object[] _user = new object[2];
            _user[0] = this.txtUserName.Text;
            _user[1] = this.txtUserPassWord.Text;
            if (dllUserInfoManager.validatePassWord(_user) > 0)
            {
                object[] _value = new object[11];//定义一个数组
                _value[0] = Convert.ToInt32(this.hId.Value);
                _value[1] = txtUserName.Text;
                //根据部门名称查询部门ID和兼职部门ID
                if (this.txtDepartment.Value.Contains(",") && this.txtPartTimeDepartment.Value.Contains(","))
                {
                    ScriptManager.RegisterClientScriptBlock(this.btnOk, this.btnOk.GetType(), "open", "alert('部门或兼职部门只能选择一个')", true);
                    return;
                }
                object[] _valueDepartment = new object[1];
                _valueDepartment[0] = this.txtDepartment.Value;
                DataTable _department = dllDepartmentInfoManager.get(DepartmentInfoManager.field.DepartmentName.ToString(), _valueDepartment);
                if (_department.Rows.Count > 0)
                {
                    _value[2] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                }
                else
                {
                    _value[2] = 0;
                }
                _valueDepartment[0] = this.txtPartTimeDepartment.Value;
                _department = dllDepartmentInfoManager.get(DepartmentInfoManager.field.DepartmentName.ToString(), _valueDepartment);
                if (_department.Rows.Count > 0)
                {
                    _value[3] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                }
                else
                {
                    _value[3] = 0;
                }
                _value[4] = this.txtMasterJob.Value.Trim();
                _value[5] = this.txtSlaveJob.Value.Trim();
                _value[6] = drpPostLevel.SelectedItem.Text;
                _value[7] = int.Parse(drpIsDepartmentManager.SelectedValue.ToString());
                _value[8] = txtRealName.Text;
                _value[9] = this.drpRole.SelectedItem.Text;
                _value[10] = this.txtItCode.Text.Trim();
                int result = dllUserInfoManager.edit(UserInfoManager.field.UserPassWord.ToString(), _value);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("修改用户未成功，请重试！");
                }
                else
                {
                    BindGridView();
                }

            }
            else
            {
                if (this.txtUserName.Text == "admin" || this.txtUserName.Text == "system")
                {
                    object[] _value = new object[2];
                    _value[0] = this.txtUserName.Text;
                    _value[1] = BLL.Authentication.EncryptPassword(this.txtUserPassWord.Text, Authentication.EncryptType.MD5);
                    _value[1] = this.txtUserPassWord.Text;
                    int result = dllAuthentication.editUserPassWord(_value);
                    if (result == 0)
                    {
                        Utility.Error.RedirectErrorPage("修改用户未成功，请重试！");
                    }
                    else
                    {
                        BindGridView();
                    }
                }
                else
                {

                    object[] _value = new object[12];//定义一个数组
                    _value[0] = Convert.ToInt32(this.hId.Value);
                    _value[1] = txtUserName.Text;
                    //_value[2] = BLL.Authentication.EncryptPassword(this.txtUserPassWord.Text, Authentication.EncryptType.MD5);
                    _value[2] = this.txtUserPassWord.Text;
                    //根据部门名称查询部门ID和兼职部门ID
                    if (this.txtDepartment.Value.Contains(",") && this.txtPartTimeDepartment.Value.Contains(","))
                    {
                        ScriptManager.RegisterClientScriptBlock(this.btnOk, this.btnOk.GetType(), "open", "alert('部门或兼职部门只能选择一个')", true);
                        return;
                    }
                    object[] _valueDepartment = new object[2];
                    _valueDepartment[0] = this.txtDepartment.Value;
                    _valueDepartment[1] = this.txtPartTimeDepartment.Value;
                    DataTable _department = dllDepartmentInfoManager.get(DepartmentInfoManager.field.DepartmentName.ToString(), _valueDepartment);
                    _value[3] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                    _value[4] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                    if (_department.Rows.Count > 0)
                    {
                        _value[3] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                        _value[4] = int.Parse(_department.Rows[0]["DepartmentId"].ToString());
                    }
                    else
                    {
                        _value[3] = 0;
                        _value[4] = 0;
                    }
                    _value[5] = this.txtMasterJob.Value.Trim();
                    _value[6] = this.txtSlaveJob.Value.Trim();
                    _value[7] = drpPostLevel.SelectedItem.Text;
                    _value[8] = int.Parse(drpIsDepartmentManager.SelectedValue.ToString());
                    _value[9] = txtRealName.Text;
                    _value[10] = this.drpRole.SelectedItem.Text;
                    _value[11] = this.txtItCode.Text.Trim();
                    int result = dllUserInfoManager.edit(UserInfoManager.field.UserId.ToString(), _value);
                    if (result == 0)
                    {
                        Utility.Error.RedirectErrorPage("修改用户未成功，请重试！");
                    }
                    else
                    {
                        BindGridView();
                    }
                }
            }

        }
    }

    /// <summary>
    /// 清空
    /// </summary>
    void clear()
    {
        this.txtUserName.Text = "";
        this.txtUserPassWord.Text = "";
        this.txtReUserPassWord.Text = "";
        this.txtDepartment.Value = "";
        this.txtPartTimeDepartment.Value = "";
        this.txtMasterJob.Value = "";
        this.txtSlaveJob.Value = "";
    }

    /// <summary>
    /// 返回事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnchongzhi_Click(object sender, EventArgs e)
    {
        Response.Redirect("User_Manager.aspx");

    }






    /// <summary>
    /// 新增人员按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-17</date>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        this.txtUserName.Text = "";
        this.txtUserName.Enabled = true;
        this.txtRealName.Text = "";
        this.txtUserPassWord.Attributes["value"] = "";
        this.txtReUserPassWord.Attributes["value"] = "";
        this.txtReUserPassWord.Text = "";
        this.txtUserPassWord.Text = "";
        this.txtDepartment.Value = "";
        this.txtPartTimeDepartment.Value = "";
        this.txtSlaveJob.Value = "";
        this.txtMasterJob.Value = "";
        BindDropDownList();
        this.hId.Value = "";
    }

    /// <summary>
    /// GridView选择行事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvUserName_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        this.hId.Value = this.gdvUserName.Rows[e.NewSelectedIndex].Cells[1].Text;
        Bind(this.hId.Value);
    }


    /// <summary>
    /// GridView行创建事件，同时修改鼠标经过颜色和绑定SelectedIndexChanging事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvUserName_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标进入行时
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor='hand';");
            //鼠标离开行时
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
            //任意行都为选择行
            e.Row.Attributes.Add("onclick", "__doPostBack('gdvUserName','Select$" + e.Row.RowIndex + "')");
        }
    }
    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click1(object sender, EventArgs e)
    {
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        {
            CheckBox _ckb = (CheckBox)this.gdvUserName.Rows[i].Cells[0].FindControl("chkSelect");
            if (_ckb.Checked == true)
            {
                _count++;
                if (this.gdvUserName.Rows[i].Cells[2].Text == "admin" || this.gdvUserName.Rows[i].Cells[2].Text == "")
                {
                    Utility.HttpHelp.alert("系统管理员或计划管理员不可以删除", Page);
                    return;
                }
                object[] _value = new object[1];
                _value[0] = Convert.ToInt32(this.gdvUserName.Rows[i].Cells[1].Text);
                _valueList.Add(_value);
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要删除的员工", Page);
        }
        if (_count > 0 && _valueList.Count > 0)
        {
            int result = dllUserInfoManager.delWithTransaction(UserInfoManager.field.UserId.ToString(), _valueList);
            if (result < 0)
            {
                Utility.Error.RedirectErrorPage("删除员工信息未成功，请重试！");
            }
            else
            {
                Response.Redirect("User_Manager.aspx");
            }
        }
    }
    /// <summary>
    /// 在职离职的选择事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpIsDimission_SelectedIndexChanged1(object sender, EventArgs e)
    {
        if (this.drpIsDimission.SelectedItem.Text == "在职")
        {
            this.btnUnDimission.Enabled = false;
            this.btnIsDimission.Enabled = true;
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get();
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();

        }
        if (this.drpIsDimission.SelectedItem.Text == "离职")
        {
            this.btnUnDimission.Enabled = true;
            this.btnIsDimission.Enabled = false;

            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get(UserInfoManager.field.IsDimission.ToString(), _value);
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();
        }
        for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        {
            if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "是";
            }
            else
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "否";
            }
        }
    }


    /// <summary>
    /// 查询按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        ////该事件需要两个参数，一个输入的关键字，另一个是判断的查询条件
        ////声明一个Datatable，
        //DataTable _select = new DataTable();
        ////第一个参数：获得输入的关键字
        //object[] _value = new object[1];

        ////第二个参数：判断查询条件
        //if (this.drpSelect.SelectedItem.Text == "选择查询条件")
        //{
        //    Utility.HttpHelp.alert("请选择查询条件", Page);
        //    _select = dllUserInfoManager.get();
        //}
        //if (this.drpSelect.SelectedItem.Text == "登录名称")
        //{
        //    _value[0] = txtSelect_Content.Text.Trim();
        //    _value[0] = "%" + _value[0] + "%";
        //    _select = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
        //}
        //if (this.drpSelect.SelectedIndex == 2)
        //{
        //    _value[0] = txtSelect_Content.Text.Trim();
        //    _value[0] = "%" + _value[0] + "%";
        //    _select = dllUserInfoManager.get(UserInfoManager.field.RealName.ToString(), _value);

        //}
        //if (this.drpSelect.SelectedItem.Text == "人员编号")
        //{
        //    _value[0] = Convert.ToInt32(txtSelect_Content.Text.Trim());
        //    _select = dllUserInfoManager.get(UserInfoManager.field.UserId.ToString(), _value);

        //}
        //if (this.drpSelect.SelectedItem.Text == "主岗名称")
        //{
        //    _value[0] = this.drpTarget.SelectedItem.Text;
        //    _select = dllUserInfoManager.get(UserInfoManager.field.MasterJob.ToString(), _value);

        //}
        //if (this.drpSelect.SelectedItem.Text == "职位级别")
        //{
        //    _value[0] = this.drpTarget.SelectedItem.Text;
        //    _select = dllUserInfoManager.get(UserInfoManager.field.PostLevel.ToString(), _value);

        //}
        //if (this.drpSelect.SelectedItem.Text == "部门名称")
        //{
        //    if (this.txtContent.Value.Length > 0)
        //    {
        //        _value[0] = this.txtContent.Value.Trim();
        //        _select = dllUserInfoManager.getUserInfoByDepartmentName(_value);
        //    }
        //    else
        //    {
        //        _select = dllUserInfoManager.get();
        //    }

        //}
        //if (this.drpSelect.SelectedItem.Text == "副岗名称")
        //{
        //    _value[0] = this.drpTarget.SelectedItem.Text;
        //    _select = dllUserInfoManager.get(UserInfoManager.field.PartTimeDepartmentId.ToString(), _value);
        //}

        ////查询的结果绑定到gridview中
        //this.gdvUserName.DataSource = _select;
        //this.gdvUserName.DataBind();
        //for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        //{
        //    if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
        //    {
        //        this.gdvUserName.Rows[i].Cells[10].Text = "是";
        //    }
        //    else
        //    {
        //        this.gdvUserName.Rows[i].Cells[10].Text = "否";
        //    }
        //}
        BindGridView();
    }


    /// <summary>
    /// 搜索条件改变项事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-26</date>
    protected void drpSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.drpTarget.Visible = false;
        this.txtSelect_Content.Text = "";
        this.txtContent.Visible = false;

        if (this.drpSelect.SelectedItem.Text == "主岗名称")
        {
            this.drpTarget.Visible = true;
            this.txtSelect_Content.Visible = false;
            this.drpTarget.DataSource = dllJobManager.get();
            this.drpTarget.DataTextField = "JobName";
            this.drpTarget.DataValueField = "JobId";
            this.drpTarget.DataBind();
            return;
        }
        if (this.drpSelect.SelectedItem.Text == "职位级别")
        {
            this.drpTarget.Visible = true;
            this.txtSelect_Content.Visible = false;
            ListItem _li1 = new ListItem("总裁");
            ListItem _li2 = new ListItem("副总裁");
            ListItem _li3 = new ListItem("部门经理");
            ListItem _li4 = new ListItem("副经理");
            ListItem _li5 = new ListItem("主管");
            ListItem _li6 = new ListItem("职员");
            this.drpTarget.Items.Clear();
            this.drpTarget.Items.Add(_li1);
            this.drpTarget.Items.Add(_li2);
            this.drpTarget.Items.Add(_li3);
            this.drpTarget.Items.Add(_li4);
            this.drpTarget.Items.Add(_li5);
            this.drpTarget.Items.Add(_li6);
            return;
        }
        if (this.drpSelect.SelectedItem.Text == "部门名称")
        {
            this.drpTarget.Visible = false;
            this.txtSelect_Content.Visible = false;
            this.txtContent.Visible = true;
            this.drpTarget.DataSource = dllDepartmentInfoManager.getNoTree();
            this.drpTarget.DataTextField = "DepartmentName";
            this.drpTarget.DataValueField = "DepartmentId";
            this.drpTarget.DataBind();
            return;
        }
        if (this.drpSelect.SelectedItem.Text == "副岗名称")
        {
            this.drpTarget.Visible = true;
            this.txtSelect_Content.Visible = false;
            this.drpTarget.DataSource = dllJobManager.get();
            this.drpTarget.DataTextField = "JobName";
            this.drpTarget.DataValueField = "JobId";
            this.drpTarget.DataBind();
            return;
        }
        this.drpTarget.Items.Clear();
        this.drpTarget.Visible = false;
        this.txtSelect_Content.Enabled = true;
        this.txtSelect_Content.Visible = true;
    }



    /// <summary>
    /// 停用用户事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-3-11</date>
    protected void btnIsDimission_Click(object sender, EventArgs e)
    {
        if (this.hId.Value.Length == 0)
        {
            for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
            {
                //声明一个checkbox对象，该对象等于gridview内当前行的checkbox对象
                //等于后面加(CheckBox)，是为了强制转换成checkbox控件
                //等于后面返回的类型是Control（控件）类型，可以转换成任何控件类型的
                CheckBox _ckb = (CheckBox)this.gdvUserName.Rows[i].Cells[0].FindControl("chkSelect");
                //如果CheckBox被选中
                if (_ckb.Checked == true)
                {
                    int result = dllUserInfoManager.Dimission(Convert.ToInt32(this.gdvUserName.Rows[i].Cells[1].Text));
                    if (result < 0)
                    {
                        Utility.Error.RedirectErrorPage("停用员工信息未成功，请重试！");
                    }
                }
            }
        }
        else
        {
            int result = dllUserInfoManager.Dimission(Convert.ToInt32(this.hId.Value));
            if (result < 0)
            {
                Utility.Error.RedirectErrorPage("停用员工信息未成功，请重试！");
            }
        }
        if (this.drpIsDimission.SelectedItem.Text == "在职")
        {
            this.btnUnDimission.Enabled = false;
            this.btnIsDimission.Enabled = true;
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get();
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();

        }
        if (this.drpIsDimission.SelectedItem.Text == "离职")
        {
            this.btnUnDimission.Enabled = true;
            this.btnIsDimission.Enabled = false;

            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get(UserInfoManager.field.IsDimission.ToString(), _value);
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();
        }
        for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        {
            if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "是";
            }
            else
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "否";
            }
        }
    }

    /// <summary>
    /// 解除停用事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUnDimission_Click(object sender, EventArgs e)
    {
        if (this.hId.Value.Length == 0)
        {
            for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
            {
                //声明一个checkbox对象，该对象等于gridview内当前行的checkbox对象
                //等于后面加(CheckBox)，是为了强制转换成checkbox控件
                //等于后面返回的类型是Control（控件）类型，可以转换成任何控件类型的
                CheckBox _ckb = (CheckBox)this.gdvUserName.Rows[i].Cells[0].FindControl("chkSelect");
                //如果CheckBox被选中
                if (_ckb.Checked == true)
                {
                    int result = dllUserInfoManager.UnDimission(Convert.ToInt32(this.gdvUserName.Rows[i].Cells[1].Text));
                    if (result < 0)
                    {
                        Utility.Error.RedirectErrorPage("启用员工信息未成功，请重试！");
                    }
                }
            }
        }
        else
        {
            int result = dllUserInfoManager.UnDimission(Convert.ToInt32(this.hId.Value));
            if (result < 0)
            {
                Utility.Error.RedirectErrorPage("启用员工信息未成功，请重试！");
            }
        }
        if (this.drpIsDimission.SelectedItem.Text == "在职")
        {
            this.btnUnDimission.Enabled = false;
            this.btnIsDimission.Enabled = true;
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get();
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();

        }
        if (this.drpIsDimission.SelectedItem.Text == "离职")
        {
            this.btnUnDimission.Enabled = true;
            this.btnIsDimission.Enabled = false;

            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.drpIsDimission.SelectedValue);
            DataTable IsDimission = dllUserInfoManager.get(UserInfoManager.field.IsDimission.ToString(), _value);
            this.gdvUserName.DataSource = IsDimission;
            this.gdvUserName.DataBind();
        }
        for (int i = 0; i < this.gdvUserName.Rows.Count; i++)
        {
            if (this.gdvUserName.Rows[i].Cells[10].Text == "1")
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "是";
            }
            else
            {
                this.gdvUserName.Rows[i].Cells[10].Text = "否";
            }
        }
    }

}
